//
//  SaleContentCell.m
//  SmallEasyLife
//
//  Created by qianfeng on 15/10/23.
//  Copyright © 2015年 GXK. All rights reserved.
//

#import "SaleContentView.h"
#import "Masonry.h"
#import "SaleLeftListView.h"
#import "SaleRightListView.h"

@interface SaleContentView ()<UIScrollViewDelegate>

@property (weak, nonatomic) IBOutlet UIScrollView *contentScrollView;

@property (weak, nonatomic) SaleLeftListView * leftListView;
@property (weak, nonatomic) SaleRightListView * rightListView;



@end

@implementation SaleContentView

- (void)setLeftDataArray:(NSArray *)leftDataArray
{
    if (_leftDataArray != leftDataArray) {
        _leftDataArray = leftDataArray;
        //传递数据
        self.leftListView.dataArray = leftDataArray;
    }
}
- (void)setRightDataArray:(NSArray *)rightDataArray
{
    if (_rightDataArray != rightDataArray) {
        _leftDataArray = rightDataArray;
        //传递数据
        self.rightListView.dataArray = rightDataArray;
    }
}
- (void)setOwnerViewController:(UIViewController *)ownerViewController
{
    _ownerViewController = ownerViewController;
    self.leftListView.ownerViewController = ownerViewController;
    self.rightListView.ownerViewController = ownerViewController;
}

- (SaleLeftListView *)leftListView
{
    if (_leftListView == nil) {
        SaleLeftListView * leftListView = [[SaleLeftListView alloc] initWithFrame:CGRectZero];
        
        _leftListView = leftListView;
        
        [self.contentScrollView addSubview:leftListView];
        
        [leftListView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(self.contentScrollView.mas_top);
            make.left.equalTo(self.contentScrollView.mas_left);
            make.width.equalTo(self.contentScrollView.mas_width);
            make.height.equalTo(self.contentScrollView.mas_height);
        }];
        
        leftListView.backgroundColor = [UIColor redColor];
        
    }
    return _leftListView;
}
- (SaleRightListView *)rightListView
{
    if (_rightListView == nil) {
        SaleRightListView * rightListView = [[SaleRightListView alloc] initWithFrame:CGRectZero];
        _rightListView = rightListView;
        [self.contentScrollView addSubview:rightListView];
        
        [rightListView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(self.leftListView.mas_top);
            make.left.equalTo(self.leftListView.mas_right);
            make.width.equalTo(self.contentScrollView.mas_width);
            make.height.equalTo(self.contentScrollView.mas_height);
        }];
        
        rightListView.backgroundColor = [UIColor orangeColor];
    }
    return _rightListView;
}

- (void)awakeFromNib {
//    // Initialization code
    self.leftListView;
    self.rightListView;
    self.contentScrollView.pagingEnabled = YES;
    self.contentScrollView.showsHorizontalScrollIndicator = NO;
    self.contentScrollView.showsVerticalScrollIndicator = NO;
    self.contentScrollView.delegate = self;
    
    self.contentScrollView.contentSize = CGSizeMake([UIScreen mainScreen].bounds.size.width * 2, 1);
    
}
- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
    if (scrollView == self.contentScrollView) {
        CGFloat width = [UIScreen mainScreen].bounds.size.width;
        NSUInteger index = scrollView.contentOffset.x / width;
        
        if (self.delegate) {
            [self.delegate saleContentCellScrollToPage:index];
        }
    }
}



@end
